package cn.zcx;

import java.util.concurrent.TimeUnit;

/**
 * description:证明volatile不是原子操作
 * author:zcx
 * lenovo
 * 时间：2022.02.08.09.44
 */
public class T28 {
    /*volatile*/ boolean running = true; //对比一下有无volatile的情况下，整个程序运行结果的区别
    void m() {
        System.out.println("m start");
        while(running) {
			/*
			try {
				TimeUnit.MILLISECONDS.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}*/
        }
        System.out.println("m end!");
    }

    public static void main(String[] args) {
        T28 t = new T28();
        new Thread(t::m, "t1").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.running = false;
    }
}
